package org.finesys.common.tenant.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.finesys.common.security.core.constant.TenantConstants;
import org.finesys.common.tenant.support.TenantContextHolder;
import org.springframework.util.ObjectUtils;

/**
 * 传递feign租户请求头
 */
public class FeignTenantInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        if (!ObjectUtils.isEmpty(TenantContextHolder.getTenantId())) {
            requestTemplate.header(TenantConstants.TENTANT_ID, TenantContextHolder.getTenantId().toString());
        }
    }
}
